#include<iostream>
#include<string>
#include<queue>
#include<stack>
#define Maxsize 100
using namespace std;
typedef struct node{
	int data;
	struct node *lchild;
	struct node *rchild;
}BTNode;
typedef BTNode *BTree;
void createBTree(BTree &BT,string str);
int WPL(BTree &T,int depth);
int wpl=0;
//void LevelOrder(BTree BT);
int main()
{
	string str;
	BTree BT;
	cin>>str;
	createBTree(BT,str);
	if(BT!=NULL) 
   {
	WPL(BT,0);
	cout<<wpl;
	}
	else
	cout<<"0"; 
	return 0;
}
void createBTree(BTree &BT,string str)
{
	int i=1;
	BTree T;
	queue<BTree> Q;
	if(str[1]=='#'||str[1]=='\0')
	BT=NULL;
	else 
	{
		BT=new BTNode;
		BT->data=str[i]-'0';
		BT->lchild=BT->rchild=NULL;
		Q.push(BT); 
	}
	while(!Q.empty() )
	{
		i++;
		if(str[i]=='\0')
		break;
		T=Q.front();
		while(T==NULL)
		{
		Q.pop();
		T=Q.front();
		i=i+2;
		}
		Q.pop();
	//	i++;
		if(str[i]=='\0')
		break;
		if(str[i]=='#')
		{
		T->lchild=NULL;
	    Q.push(T->lchild); 
		}
		else
		{
			T->lchild=new BTNode;
			T->lchild->data =str[i]-'0';
			T->lchild->lchild=T->lchild->rchild=NULL;
			Q.push(T->lchild);
		}
		i++;
		if(str[i]=='\0')
		break;
		if(str[i]=='#')
		{
		T->rchild=NULL;
	    Q.push(T->rchild); 
		}
		else
		{
			T->rchild=new BTNode;
			T->rchild->data =str[i]-'0';
			T->rchild->lchild=T->rchild->rchild=NULL;
			Q.push(T->rchild);
		}
	}
	
}
int WPL(BTree &T,int depth)
{
	if(T==NULL)
	return 0;
	if(T->lchild==NULL&&T->rchild==NULL)
	wpl=wpl+T->data*depth;
	else
	{
		WPL(T->lchild,depth+1);
		WPL(T->rchild,depth+1); 
	}
} 
